Code Review replication

This topic describes how to work with Gerrit Code Review replication.

Enable Gerrit Code Review replication

Enable Gerrit Code Review ReplicationGerrit Code Review can be configured to push changes from Git repositories to one or more remote hosts. This section describes how to enable Gerrit Code Review replication in GitCentric. For general concepts related to Gerrit Code Review replication, refer to the Gerrit Code Review documentation.

The basic procedure for enabling Gerrit Code Review replication is summarized here:

  1. Register the SSH public key representing the GitCentric bridge account with the Gerrit Code Review administrator’s account.
  2. Ensure that the server running Gerrit Code Review has SSH access to the server to which changes will be replicated. If the machine running Gerrit Code Review has never connected to the replication server, it will be listed as an unknown host and Gerrit Code Review will close the connection.
  3. Modify the sample Git-style configuration file, replication.config, that is installed with GitCentric.
  4. Stop and restart GitCentric.

Back to top

Modifying the replication.config File

Gerrit Code Review uses a replication.config file to identify the URL of the server to which changes will be replicated. For example:

[remote "host-one"]
url = gerrit2@host-one.example.com:/some/path/${name}.git

A sample replication.config is installed to <gc_home>site/etc. To use this file:

  1. Uncomment the example.

    Tip: Consider copying the example and using that copy to specify the URLs for one or more remote hosts.

  2. Change the sample values for values applicable to your environment.
  3. Stop Gerrit Code Review, which you can do by stopping the Tomcat web server. For example:
    cd <ac_home>/WebUI/tomcat/bin
    ./shutdown.sh
  4. Restart Gerrit Code Review. For example:
    cd <ac_home>/WebUI/tomcat/bin
    ./startup.sh

    Note: Make sure that the user starting Tomcat web server has write access to the logs, temp, webapps, and work directories in <ac_home>/WebUI/tomcat. This user should have read access to all other Tomcat web server directories and files.

Back to top

Set up Gerrit code review garbage collection

Gerrit Code Review garbage collection (gerrit gc) is a command that converts loose objects to packed, and that also removes unused objects. We recommend that you run garbage collection on a regular basis to avoid performance problems associated with loose objects that occur over time.

This topic provides general examples of cron jobs you can use to set up garbage collection for your site. Syntax and supported features for cron jobs can vary across platforms. For more information, refer to cron and crontab documentation for your platform.

Note: Consider running garbage collection on all of your projects on a regular basis. Choose a "quiet" time that will be unlikely to interfere with repository users.

Gerrit gc Syntax

The basic syntax for the garbage collection command is:

ssh -p <port> <user>@<host> gerrit gc [--all] [ <project> ... ]
<port> GitCentric port number, typically 29418.
<user> User with Gerrit Code Review Administrate Server privileges.
<host> Name of the GitCentric host machine.
--all runs garbage collection on all projects in the repository.
<project> Name of one or more individual projects in which you want to run garbage collection.

cron job Examples

You use cron jobs to execute commands, like gerrit gc, on a scheduled basis. The cron job format is a sequence of five fields used to specify day, time, and frequency. The sixth is used to specify the command:

Field Description Allowed Values
MIN Minute of the hour 0 to 59, *
HOUR Hour of the day 0 to 23, *
DOM Day of the month 1 to 31, *
MON Month 1 to 12, *
DOW Day of the week 0 to 6; *; sun, mon, tue, wed, thu, fri, sat
CMD Command The command to be executed

The following examples show how you can use cron jobs to run garbage collection on your Gerrit projects. In these examples, comet is the name of the GitCentric GUI host machine.

Run garbage collection on all projects at midnight every day of the week.

0 0 * * * ssh -p 29418 admin@comet gerrit gc --all

Tip: You can use the keyword @daily to express 0 0 * * *.

Run garbage collection on all projects weekly at midnight Sunday.

0 0 * * sun -p 29418 admin@comet gerrit gc --all

Tip: You can use the keyword @weekly to express 0 0 * * 0 (which is the equivalent of 0 0 * * sun).

Run garbage collection on acme and phoenix projects Monday through Friday at 1:30 a.m.

0 0 * * 1-5 ssh -p 29418 admin@comet gerrit gc acme phoenix

Back to top